#!/usr/bin/python3
# coding: utf-8
# file: pyquery_.py
# 2018-06-12
from pyquery import PyQuery as pq


def parse_html(file_name):
	'''解析html文件'''
	html = ''
	doc = None
	with open(file_name, encoding='utf-8') as f:
		html = f.read()
	if html:
		doc = pq(html, parser='html')
	return doc

def get_text(doc, css):
	'''获取文本信息'''
	t = doc(css).text()
	print(t)

def get_attr(doc, attr):
	'''获取属性值'''
	a = doc.attr(attr)
	print(a)



if __name__ == '__main__':
	file_name = '111.html'
	doc = parse_html(file_name)
	if doc:
		get_text(doc, 'title')

		items = doc('meta').items()
		for item in items:
			get_attr(item, 'name')
